package com.lengxf.pay.wx.bean;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.lengxf.pay.common.bean.Param;
import lombok.Data;

import java.util.StringJoiner;

@Data
public class AppPayModel implements Param {

    private String appId;

    private String timeStamp;

    private String nonceStr;

    @JsonProperty("package")
    private String _package;

    //SHA256 with RSA
    private String signType = "RSA";

    private String paySign;

    public AppPayModel(String appId, String prepayId) {
        this.appId = appId;
        this._package = "prepay_id=" + prepayId;
        this.nonceStr = UUID.fastUUID().toString(true);
        this.timeStamp = String.valueOf(DateUtil.currentSeconds());
    }

    public String buildSignStr() {
        String delimiter = "\n";
        StringJoiner stringJoiner = new StringJoiner(delimiter);
        stringJoiner.add(this.appId)
                .add(this.timeStamp)
                .add(this.nonceStr)
                .add(this._package);
        return stringJoiner + delimiter;
    }

}
